#include"server.hpp"
#define USER "root"
#define HOST "127.0.0.1"
#define PORT 3306
#define DBNAME "gobang"
#define PASSWD "Yjl123456"

void mysql_test()
{
    MYSQL* mysql = mysql_util::mysql_create(PASSWD,DBNAME,HOST,USER,PORT);
    //mysql_util::mysql_exec(mysql,"insert into stu values(1,'杨龙')");
    bool ex = mysql_util::mysql_exec(mysql,"select * from stu");
    if(ex == false) return;
    mysql_util::mysql_destroy(mysql);
}
void Json_test()
{
    Json::Value root;
    std::string jsval;
    root["姓名"] = "dragon";
    root["ID"] = "2";
    //对于Json来说如果一个key下有多个内容，则使用append
    root["interest"].append("muscle building");
    root["interest"].append("guita");
    root["interest"].append("singing");
    json_util::serialize(root,jsval);
    DLOG("%s",jsval.c_str());
    
    Json::Value uns;
    json_util::unserialize(uns,jsval);
    
    printf("姓名：%s\nID:%s\n",uns["姓名"].asCString(),uns["ID"].asCString());
    std::cout<<"兴趣爱好:";
    for(int i = 0;i<uns["interest"].size();i++)
    {
        std::cout<<uns["interest"][i]<<' ';
    }
    std::cout<<std::endl;
}
void str_test()
{
    std::string str = "123,231,,,422,,,123,";
    std::string sep = ",";
    std::vector<std::string> res;
    int size = str_util::spilt(str,sep,res);
    std::cout<<size<<std::endl;
    for(auto s : res) ILOG("%s",s.c_str());
}
void file_test()
{
    std::string filename = "Makefile";
    std::string rec;
    file_util::read(filename,rec);
    ILOG("%s",rec.c_str());
}
void db_test()
{
    Json::Value JV;
    JV["username"] = "aron";
    JV["passwd"] = "aron1234";
    user_table user(PASSWD,DBNAME,HOST,USER,PORT);
    //user.insert(JV);
    // bool ret = user.login(JV);
    // std::cout<<ret<<std::endl;
    // Json::Value scid;
    // user.select_user_by_id(1,scid);
    // DLOG("%s",scid["username"].asCString());
    
}
void online_test()
{
    wsserver_t::connection_ptr conn;
    uint64_t uid = 2;
    online_manager om;
    om.enter_hall(uid,conn);
    om.is_in_hall(uid);
    om.exit_hall(uid);
    om.is_in_hall(uid);
}
void room_test()
{
    online_manager om;
    user_table ut(PASSWD,DBNAME,HOST,USER,PORT);
    room rm1(1,&om,&ut);
}
void room_manager_test()
{
    online_manager om;
    user_table ut(PASSWD,DBNAME,HOST,USER,PORT);
    room_manager rm(&om,&ut);
}
void session_manager_test()
{
    wsserver_t ws;
    session_manager sm(&ws);
}
void matcher_test()
{
    online_manager om;
    user_table ut(PASSWD,DBNAME,HOST,USER,PORT);
    room_manager rm(&om,&ut);
    matcher<uint64_t> mc(&rm,&ut,&om);
}
int main()
{
    char str[] = {0};
    ELOG("Chinese NO.1");
    //mysql_test();
    gobang_server _server(PASSWD,DBNAME,HOST,USER,PORT);
    _server.start(8085);
    return 0;
}